﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lfm.EndPoints
{
    public class Album
    {
        /// <summary>
        /// Gets info for an Artist
        /// </summary>
        /// <param name="Artist">Artist Name</param>
        /// <param name="Album">Album Name</param>
        /// <param name="Autocorrect">Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response.</param>
        /// <returns>Artist</returns>
        public static async Task<lfm.Album> getInfo(String Artist, String Album, Boolean? Autocorrect)
        {
            String s = String.Format("{0}&method=album.getInfo&artist={1}&album={2}", Base.APIUrl, Uri.EscapeDataString(Artist), Uri.EscapeDataString(Album));
            if (Autocorrect.HasValue && Autocorrect.Value) s += "&autocorrect=1";

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Album.getInfo(await Base.DownloadString(u));;
        }

        /// <summary>
        /// Gets a list of the buy links for an album 
        /// </summary>
        /// <param name="Artist">The artist name</param>
        /// <param name="Album">The album name</param>
        /// <param name="Country">A country name, as defined by the ISO 3166-1 country names standard.</param>
        /// <param name="Autocorrect">Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response</param>
        /// <returns>Buy links for this album</returns>
        public static async Task<List<lfm.Link>> getBuyLinks(String Artist, String Album, String Country, Boolean? Autocorrect)
        {
            String s = String.Format("{0}&method=album.getbuylinks&artist={1}&album={2}&country={3}", Base.APIUrl, Uri.EscapeDataString(Artist), Uri.EscapeDataString(Album), Uri.EscapeDataString(Country));
            if (Autocorrect.HasValue && Autocorrect.Value) s += "&autocorrect=1";

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getBuyLinks(await Base.DownloadString(u));
        }

        /// <summary>
        /// Gets a list of shouts for an album 
        /// </summary>
        /// <param name="Artist">The artist name</param>
        /// <param name="Album">The album name</param>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <param name="Autocorrect">Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response</param>
        /// <returns>Shouts for this artist</returns>
        public static async Task<List<lfm.Shout>> getShouts(String Artist, String Album, Int32? Page, Int32? Limit, Boolean? Autocorrect)
        {
            String s = String.Format("{0}&method=album.getShouts&artist={1}&album={2}", Base.APIUrl, Uri.EscapeDataString(Artist), Uri.EscapeDataString(Album));
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Autocorrect.HasValue && Autocorrect.Value) s += "&autocorrect=1";

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getShouts(await Base.DownloadString(u)); ;
        }

        /// <summary>
        /// Gets a list of the most popular tags for an album 
        /// </summary>
        /// <param name="Artist">The artist name</param>
        /// <param name="Album">The album name</param>
        /// <param name="Autocorrect">Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response</param>
        /// <returns>Top Tags for this album</returns>
        public static async Task<List<lfm.Tag>> getTopTags(String Artist, String Album, Boolean? Autocorrect)
        {
            String s = String.Format("{0}&method=album.gettoptags&artist={1}&album={2}", Base.APIUrl, Uri.EscapeDataString(Artist), Uri.EscapeDataString(Album));
            if (Autocorrect.HasValue && Autocorrect.Value) s += "&autocorrect=1";

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getTags(await Base.DownloadString(u));
        }

        /// <summary>
        /// Gets a list of search results for an album 
        /// </summary>
        /// <param name="Album">The album name</param>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Search results for album</returns>
        public static async Task<List<lfm.Album>> search(String Album, Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=album.search&album={1}", Base.APIUrl, Uri.EscapeDataString(Album));
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Album.search(await Base.DownloadString(u));
        }
    }
}
